#include "StdAfx.h"

#include "MathUtils/Ray.h"
#include "ColorUtils/Color.h"

#include "FirstIntersectionResult.h"
#include "SecondIntersectionResult.h"
#include "Intersectable.h"

#include "Plain.h"

Plain::Plain(const Ray& param, const Color& color) : _ray(param), _color(color), _pointTimesDirection(param.D.ScalarProduct(param.P))
{}

void Plain::ColorAtIntersection(SecondIntersectionResult& result, const Point&, const Ray&)
{
	result.ColorAtPoint = _color;
}

Direction Plain::NormalAtPoint(FirstIntersectionResult&, const Point&)
{
	return _ray.D;
}

void Plain::WhereIntersects(const Ray& ray, FirstIntersectionResult& result)
{
	double temp = ray.D.ScalarProduct(_ray.D);
	if (temp == 0)
		result.Set(this);
	else
		result.Set((_pointTimesDirection - ray.P.ScalarProduct(_ray.D)) / temp, this);
}

Plain::~Plain()
{}
